package com.hutu.model.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * App 应用类型枚举
 */
@Getter
public enum AppTypeEnum {

    /**
     * 应用类型在前 打分类: 0,   测评类: 1
     * 评分策略    自定义: 0,   AI: 1
     */
    SCORE("00","打分类"),
    TEST("10","测评类"),
    AI_TEST("01","AI测评类"),
    AI_SCORE("11","AI打分类");

    private final String type;
    private final String text;

    private static Map<String, AppTypeEnum> cache;

    static {
        cache = Arrays.stream(AppTypeEnum.values()).collect(Collectors.toMap(AppTypeEnum::getType, Function.identity()));
    }
    AppTypeEnum(String type,String text) {
        this.text = text;
        this.type = type;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param type
     * @return
     */
    public static AppTypeEnum getEnumByValue(String type) {
        if (ObjectUtil.isEmpty(type)) {
            return null;
        }
        for (AppTypeEnum anEnum : AppTypeEnum.values()) {
            if (Objects.equals(anEnum.type,type)) {
                return anEnum;
            }
        }
        return null;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.type).collect(Collectors.toList());
    }

    public static AppTypeEnum of(Integer type) {
        return cache.get(type);
    }

}
